package com.mj.Set;

import com.mj.file.FileInfo;
import com.mj.file.Files;

import java.util.HashMap;
import java.util.HashSet;

/**
 * @Author: LDeng
 * @Date: 2021-03-10 8:47
 */
public class Main {

    static void test1(){
        Set<Integer> listSet=new ListSet<>();
        listSet.add(10);
        listSet.add(11);
        listSet.add(11);
        listSet.add(12);
        listSet.add(10);

        listSet.traversal(new Set.Visitor<Integer>() {
            @Override
            boolean visit(Integer element) {
                System.out.println(element);
                return false;
            }
        });

        System.out.println("-----------------------------");

        Set<Integer> treeSet=new TreeSet<>();
        treeSet.add(10);
        treeSet.add(11);
        treeSet.add(11);
        treeSet.add(12);
        treeSet.add(10);
        treeSet.add(7);
        treeSet.add(22);
        treeSet.traversal(new Set.Visitor<Integer>() {
            @Override
            boolean visit(Integer element) {
                System.out.println(element);
                return false;
            }
        });
    }

    static void test2(){
        FileInfo fileInfo = Files.read("C:\\Users\\LDeng\\Desktop\\src\\java\\util",
                new String[]{"java"});
        System.out.println("文件数量："+fileInfo.getFiles());
        System.out.println("文件行数："+fileInfo.getLines());
        String[] words=fileInfo.words();
        System.out.println("总共包含单词数："+words.length);



       Times.check("listSet", new Times.Task() {
           @Override
           public void execute() {
               testSet(new ListSet<>(),words);
           }
       });

        Times.check("treeSet", new Times.Task() {
            @Override
            public void execute() {
                testSet(new TreeSet<>(),words);
            }
        });

    }

    static void testSet(Set<String> set,String[] words){

        for (int i = 0; i <words.length; i++) {
            set.add(words[i]);
        }
        System.out.println("去重后的单词数:"+set.size());

        for (int i = 0; i <words.length; i++) {
            set.contains(words[i]);
        }

        for (int i = 0; i <words.length; i++) {
            set.remove(words[i]);
        }

    }

    public static void main(String[] args) {

        //test1()
        test2();
    }
}
